package com.example.jussi.servicedemo;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;

/**
 * Created by admin on 2018/12/1.
 */

public class MyService extends Service {
    int count;
    boolean flag;

    public class MyBind extends Binder{
        public int getCount(){
            return count;
        }
        public void setCount(int arg){
            count = arg;
        }
    }

    MyBind bind = new MyBind();

    @Override
    public IBinder onBind(Intent intent) {
        return bind;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        flag = true;
        new Thread(){
            @Override
            public void run() {
                while (flag){
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    count++;
                }
            }
        }.start();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        flag = false;
    }
}
